package tron;

import java.awt.event.*;

public class Control implements KeyListener {
    Game game;

    public Control(Game game) {
	this.game = game;
    }

    public void keyTyped(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
	Snake.Direction direction = null;
	switch (e.getKeyCode()) {
	case KeyEvent.VK_UP:
	    direction = Snake.Direction.UP;
	    break;
	case KeyEvent.VK_DOWN:
	    direction = Snake.Direction.DOWN;
	    break;
	case KeyEvent.VK_LEFT:
	    direction = Snake.Direction.LEFT;
	    break;
	case KeyEvent.VK_RIGHT:
	    direction = Snake.Direction.RIGHT;
	    break;
	}
	if (direction != null)
	    game.setDirection(direction);
    }

    public void keyReleased(KeyEvent e) {
    }
}
